from django.http import JsonResponse
from django.shortcuts import render

# Create your views here.
from django.views import View

from utils import loadaddr
from .models import staff

class YuanGongView(View):
    def get(self,request):
        staffs = staff.objects.all()

        return render(request,'staff.html',{'staffs':staffs})

class AddView(View):
    def get(self,request):
        provinces = loadaddr.get_provinces()
        return render(request,'add.html',{"provinces":provinces})
    def post(self,request):
        type = request.POST.get('type', '1')
        if type == '1':
            privinceId = request.POST.get('provinceId', '110000')
            citys, areas = loadaddr.get_citys_areas_by_provinceid(privinceId)
            return JsonResponse({'citys': citys, 'areas': areas})


# class AddressView(View):
#     def post(self,request):
#         type = request.POST.get('type', '1')
#         if type == '1':
#             privinceId = request.POST.get('provinceId', '110000')
#             citys, areas = loadaddr.get_citys_areas_by_provinceid(privinceId)
#             return JsonResponse({'citys': citys, 'areas': areas})
#         elif type == '2':
#             cityId = request.POST.get('cityId', '')
#             areas = loadaddr.get_areas_by_cityid(cityId)
#             return JsonResponse({'areas': areas})

